package tpui;

import java.util.ArrayList;

public class Tablero {
	int max_X;
	int max_Y;
	public int getMax_X() {
		return max_X;
	}

	public void setMax_X(int max_X) {
		this.max_X = max_X;
	}

	public int getMax_Y() {
		return max_Y;
	}

	public void setMax_Y(int max_Y) {
		this.max_Y = max_Y;
	}

	private Ficha ficha[][];
	private ArrayList<Integer> colors;
	
	public ArrayList<Integer> getColors() {
		return colors;
	}

	public void setColors(ArrayList<Integer> colors) {
		this.colors = colors;
	}

	public Ficha[][] getFicha() {
		return ficha;
	}

	public void setFicha(Ficha[][] ficha) {
		this.ficha = ficha;
	}
	
	public Tablero(Integer x , Integer y, ArrayList<Integer> colors){
		this.setFicha(new Ficha[x][y]);
		this.setMax_Y(y-1);
		this.setMax_X(x-1);
		this.setColors(colors);
		this.cargarTablero();
	}
	
	public Ficha tomaFicha(int x, int y){
		return this.ficha[x][y];
	}
	
	public ArrayList<Ficha> dameListaParaBorrar(int x, int y){
		return this.ficha[x][y].caramelosIguales();
	}
	
	public void cargarTablero(){
		int z = (int) (Math.random() * this.colors.size());
		int x = 0;
		int y = 0;
		int max_y = this.getMax_Y();
		int max_x = this.getMax_X();
		while(!(x==max_x&& y==max_y)){
			z= (int) (Math.random() * this.colors.size());
			switch(z){
			case 0:
				this.ficha[x][y] = new Amarillo(x,y,this);
				if(x==max_x){
					x = 0;
					y++;
					}else{
					   x++;
					}
				break;
			case 1:
				this.ficha[x][y] = new Celeste(x,y,this);
				if(x==max_x){
				x = 0;
				y++;
				}else{
				   x++;
				}
				break;
			case 2:
				this.ficha[x][y]  = new Rojo(x,y,this);
				if(x==max_x){
				x = 0;
				y++;
				}else{
				   x++;
				}
				break;
			case 3:
				this.ficha[x][y]  = new Verde(x,y,this);
				if(x==max_x){
				x = 0;
				y++;
				}else{
				   x++;
				}
				break;
			case 4:
				this.ficha[x][y]  = new Violeta(x,y,this);
				if(x==max_x){
				x = 0;
				y++;
				}else{
				   x++;
				}
				break;
			default:
				this.ficha[x][y]  = new Naranja(x,y,this);
				if(x==max_x){
				x = 0;
				y++;
				}else{
				   x++;
				}
				break;
			}
		}
		
	}
}
